package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.imagemodule.ImageAD;
import com.yidiandao.business.data.imagemodule.ThreeOneImage;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.HomeThreeOneImageHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.JumpUtils;

/** 首页 3-1 图片 ListItem */
public class HomeThreeOneImageListItem
        extends DisplayListItem<HomeThreeOneImageHolder, ThreeOneImage>
        implements View.OnClickListener {

    private Activity mActivity;

    private ImageAD mImageAD1;
    private ImageAD mImageAD2;
    private ImageAD mImageAD3;
    private ImageAD mImageAD4;

    public HomeThreeOneImageListItem(ThreeOneImage s) {
        super(s);
    }

    @Override
    public void onShow(Context context, HomeThreeOneImageHolder holder) {
        mActivity = (Activity) context;

        mImageAD1 = data.getTopLeft();
        mImageAD2 = data.getTopMiddle();
        mImageAD3 = data.getTopRight();
        mImageAD4 = data.getBottom();

        ImageLoader.loadImage(context, holder.ivImage1, mImageAD1.getImage());
        ImageLoader.loadImage(context, holder.ivImage2, mImageAD2.getImage());
        ImageLoader.loadImage(context, holder.ivImage3, mImageAD3.getImage());
        ImageLoader.loadImage(context, holder.ivImage4, mImageAD4.getImage());

        holder.ivImage1.setOnClickListener(this);
        holder.ivImage2.setOnClickListener(this);
        holder.ivImage3.setOnClickListener(this);
        holder.ivImage4.setOnClickListener(this);
    }

    @Override
    public String getDisplayItemTag() {
        return HomeThreeOneImageListItem.class.getSimpleName();
    }

    @Override
    public Class<HomeThreeOneImageHolder> getViewHolderClazz() {
        return HomeThreeOneImageHolder.class;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_image_1:
                JumpUtils.clickImageAD(mActivity, mImageAD1);
                break;
            case R.id.iv_image_2:
                JumpUtils.clickImageAD(mActivity, mImageAD2);
                break;
            case R.id.iv_image_3:
                JumpUtils.clickImageAD(mActivity, mImageAD3);
                break;
            case R.id.iv_image_4:
                JumpUtils.clickImageAD(mActivity, mImageAD4);
                break;
        }
    }
}
